from django.http import HttpResponse
from utils.resFormatUtil import ResFormat
def varifyParam(*param): # email,password
    """
    参数验证装饰器
    1.校验必备参数是否录入
    2.校验参数格式是否正确
    3.发送邮件
    4.响应
    :param param:需要验证的参数
    :return:
    """
    # 装饰器 func-->get/post
    def verify(func):
        def isNone(request, *args, **kwargs): # requesr.GET.get()
            # 获取参数
            request_param = getattr(request, request.method) # getattr()获取指定对象的指定属性 request.GET/POST

            # 循环获取要检验的参数
            for i in param: # i假设-->email
                value = request_param.get(i, None) # requesr.GET.get('email')

                if not value:
                    # return HttpResponse("参数错误")
                    return ResFormat(status='PARAM_ERROR').json_response()

            return func(request, *args, **kwargs) # 回调
        return isNone
    return verify # 装饰器回调的是函数名

